package cn.wolfcode.controller;


import cn.wolfcode.wolf2w.JsonResult.JsonResult;
import cn.wolfcode.wolf2w.domain.Destination;
import cn.wolfcode.wolf2w.domain.Banner;
import cn.wolfcode.wolf2w.domain.Strategy;
import cn.wolfcode.wolf2w.domain.Travel;
import cn.wolfcode.wolf2w.query.BannerQuery;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IBannerService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private IBannerService bannerService;
    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;
    @RequestMapping("/list")
    public String list(Model model,@ModelAttribute("qo")BannerQuery qo){
        Page<Banner> page=bannerService.query(qo);
        model.addAttribute("page",page);
        //pageinfo:MyBatis插件，操作的是Mysql数据库
        //page：spring-data 的组件，操作的是mongodb数据库
        return "banner/list";
    }


    //目的地下拉框数据
    @RequestMapping("/listDests")
    @ResponseBody
    public Object listDests(){
        return destinationService.list();
    }


    //添加功能
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(Banner banner){
        bannerService.saveOrUpdate(banner);
        return JsonResult.success();
    }

    @RequestMapping("/getAllType")
    @ResponseBody
    public Object getAllType(){
        List<Strategy> sts = strategyService.list();
        List<Travel> ts = travelService.list();
        Map map=new HashMap<>();
        map.put("sts",sts);
        map.put("ts",ts);
        return JsonResult.success(map);
    }
}
